<?php
namespace Yzadmin\Controller;
use Think\Controller;
class HelpController extends CkController
{
    public function index()
    {  
       $data['helplist']= M("help")->order("sort asc,id asc")->select();
       $data['title']="帮助中心";
       $this->assign($data);
       $this->display();
    }
    
    //添加
    public function add()
    {
       $data['title']="添加帮助中心文章";
       $this->assign($data);
       $this->display();
    }

    //添加and更新公用方法
    public function add_update()
    {
        $data=I('post.');
        $help=M("help");
        $_help=$help->where(array('title'=>$data['title']))->find();
        if(!empty($_help) || $data['id']){
            //更新
          $id=get_content_id($_news,$data['id']);
          if($help->where(array("id"=>$id))->save($data)!==false)
           {
             $this->success("帮助文章文章更新成功!",U("Help/index"));
           }
        }else{
            //添加
          if($help->add($data)!==false)
           {
            $this->success("帮助文章添加成功!",U("Help/index"));
           }
        }
    }

    //更新
    public function update()
    {
        $id=I('get.id');
        $data['help']=M("help")->find($id);

        $data['title']="文章修改";
        $this->assign($data);
        $this->display();
    }


    //删除
    public function dels()
    {
      $id= I("get.id");
      if(!$id){ $this->error("请选择要删除的文章!");}
      if(M("help")->where("id=".$id)->delete()!==false)
      {
        $this->success("删除成功!",U("help/index"));
      }else{
        $this->error("删除失败!",U("help/index"));
      }
    }

}
?>